package com.jshoperxms.components.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisCluster;


/**
 * Created by wang on 2018/7/25.
 * Des:
 */
@Component
public class RedisUtils {

    @Autowired
    private JedisCluster jedisCluster;

    private static final Logger LOGGER  = LoggerFactory.getLogger(RedisUtils.class);

    public void setObject(String key,String value){
        LOGGER.info("设置redis对象：key:"+key+"value:"+value);
        jedisCluster.set(key,value);

    }

    public void setObjectEx(String key,int seconds,String value){

        jedisCluster.setex(key,seconds,value);
    }

    public String getObjectByKey(String key){
        LOGGER.info(key+"还有多少时间过期"+jedisCluster.ttl(key));
        LOGGER.info("获取key值为"+key+"的redis对象的指是"+jedisCluster.get(key));
        return jedisCluster.get(key);
    }

    public void deleteObjectByKey(String key){

        LOGGER.info("删除key值为"+key+"的redis对象");
        jedisCluster.del(key);
    }

}
